package com.ncd.form.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ncd.form.domain.LayoutVersion;
import com.ncd.form.mapper.LayoutVersionMapper;
import com.ncd.form.service.ILayoutVersionService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LayoutVersionServiceIml extends ServiceImpl<LayoutVersionMapper, LayoutVersion> implements ILayoutVersionService {


    @Override
    public List<LayoutVersion> queryList(LayoutVersion layoutVersion) {
        LambdaQueryWrapper<LayoutVersion> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ObjectUtil.isNotNull(layoutVersion.getLayoutId()),LayoutVersion::getLayoutId,layoutVersion.getLayoutId());
        wrapper.eq(ObjectUtil.isNotNull(layoutVersion.getVersionStatus()),LayoutVersion::getVersionStatus,layoutVersion.getVersionStatus());
        return this.list(wrapper);
    }

    @Override
    public Long selectMaxVersion(Long layoutId) {
        return this.baseMapper.selectMaxVersion(layoutId).longValue();
    }

    @Override
    public LayoutVersion selectActiveLayoutVersion(Long layoutId) {
        return this.baseMapper.selectOne(new LambdaQueryWrapper<LayoutVersion>()
                                         .eq(LayoutVersion::getLayoutId,layoutId)
                                         .eq(LayoutVersion::getVersionStatus,'2'));
    }
}
